package main

import (
	"fmt"
	"log"
	_ "net/http"
	"time"

	"github.com/user/go-capcut/pkg/client"
)

func main() {
	// 创建客户端
	c := client.NewClient("http://localhost:8080")

	// 创建草稿
	draftID, draftURL, err := c.CreateDraft(720, 1280, "")
	if err != nil {
		log.Fatalf("Failed to create draft: %v", err)
	}

	fmt.Printf("Created draft with ID: %s, URL: %s\n", draftID, draftURL)

	// 添加视频
	videoURL := "https://example.com/video.mp4" // 替换为实际视频URL
	trackIndex, segmentID, err := c.AddVideo(draftID, videoURL, 0, -1, -1, 100)
	if err != nil {
		log.Fatalf("Failed to add video: %v", err)
	}

	fmt.Printf("Added video to track %d with segment ID: %s\n", trackIndex, segmentID)

	// 添加音频
	audioURL := "https://example.com/audio.mp3" // 替换为实际音频URL
	trackIndex, segmentID, err = c.AddAudio(draftID, audioURL, 0, -1, -1, 100)
	if err != nil {
		log.Fatalf("Failed to add audio: %v", err)
	}

	fmt.Printf("Added audio to track %d with segment ID: %s\n", trackIndex, segmentID)

	// 添加文本
	trackIndex, segmentID, err = c.AddText(draftID, "Hello, CapCut!", "#FFFFFF", 36, 5, -1)
	if err != nil {
		log.Fatalf("Failed to add text: %v", err)
	}

	fmt.Printf("Added text to track %d with segment ID: %s\n", trackIndex, segmentID)

	// 添加图片
	imageURL := "https://example.com/image.jpg" // 替换为实际图片URL
	trackIndex, segmentID, err = c.AddImage(draftID, imageURL, 5, -1)
	if err != nil {
		log.Fatalf("Failed to add image: %v", err)
	}

	fmt.Printf("Added image to track %d with segment ID: %s\n", trackIndex, segmentID)

	// 添加特效
	effectID, err := c.AddEffect(draftID, trackIndex, segmentID, "filter", "blur", 0, -1)
	if err != nil {
		log.Fatalf("Failed to add effect: %v", err)
	}

	fmt.Printf("Added effect with ID: %s\n", effectID)

	// 等待一段时间，模拟编辑过程
	fmt.Println("Waiting for 2 seconds...")
	time.Sleep(2 * time.Second)

	// 保存草稿
	savedDraftURL, err := c.SaveDraft(draftID)
	if err != nil {
		log.Fatalf("Failed to save draft: %v", err)
	}

	fmt.Printf("Saved draft with URL: %s\n", savedDraftURL)
}
